import {initRequest, myRequest} from "../../api/myRequest";
import { actionsMap } from '../../api/url'

const $RC = 'AccountManage'
const $actions = actionsMap[$RC]
const _slat = "&%5123***&&%%$$#@";
const _defaultPassword = "123456";
const _AccountLogin = 'AccountLogin';
const AccountUser ={
	getSlat(){
		return _slat;
	},
	getDefaultPassword(){
		return _defaultPassword;
	},
	/**
	 * 登录
	 * @param param
	 * @returns  {AxiosPromise}
	 */
	login(param) {
		return myRequest(_AccountLogin,param);
	},

	/**
	 * 添加信息
	 * @param record
	 * @returns  {AxiosPromise}
	 */
	add(record) {
		return myRequest($RC,[{action: $actions.ADD, data: [record]}]);
	},

	/**
	 * 更新信息
	 * @param record
	 * @returns  {AxiosPromise}
	 */
	update(record) {
		return myRequest($RC,[{action: $actions.UPDATE, data: [record]}]);
	},

	/**
	 * 删除信息
	 * @param id
	 * @returns {Promise<*>}
	 */
	delete(filter) {
		return myRequest($RC,[{action: $actions.DELETE, ...filter}]);
	},

	/**
	 * 按Id删除信息
	 * @param ids
	 * @returns {Promise<*>}
	 */
	deleteById(id) {
		return myRequest($RC,[{action: $actions.DELETE_BY_ID, id: id}]);
	},

	/**
	 * 批量删除信息
	 * @param ids
	 * @returns {Promise<*>}
	 */
	deleteByIds(ids) {
		return myRequest($RC,[{action: $actions.DELETE_BY_IDS, ids: ids}]);
	},

	/**
	 * 查询列表
	 * @param filter
	 * @returns {Promise<*>}
	 */
	query(filter) {
		let recipient = [{action: $actions.QUERY,...filter}]
		return myRequest($RC,recipient);
	},

	/**
	 * 批量删除信息
	 * @param ids
	 * @returns {Promise<*>}
	 */
	queryByIds(ids) {
		return myRequest($RC,[{action: $actions.QUERY_BY_IDS, ids: ids}]);
	},

	/**
	 * 分页查询
	 * @param pageNumber
	 * @param pageSize
	 * @param filter
	 * @returns {Promise<unknown | void>}
	 */
	queryByPage(pageNumber, pageSize, filter) {
		let recipient = [{action: $actions.QUERY_BY_PAGE, pageNumber: pageNumber, pageSize: pageSize,...filter}]
		return myRequest($RC,recipient);
	}
}

export default AccountUser;
